import base64
import json
import pymysql
import requests
import random
from asgiref.sync import async_to_sync
from channels.layers import get_channel_layer

from utils.connect_redis import connect_redis
from utils.connect_mysql import connect_crm, connect_boss
from utils.cc_authentication import authentication
from utils.data_cleaning import reconsitution_data
from utils.redis_operation import redis_save


# 主叫号码分配
def dialing_group_usercli(dialing_group):
    try:
        print(dialing_group)
        # 连接boss数据库
        connect = connect_boss()
        cursor = connect.cursor()
        sql1 = "select tactics from zb_number_grouping where id=%s" % dialing_group
        cursor.execute(sql1)
        tactics = cursor.fetchone()
        if not tactics:
            return ""
        tactics = tactics[0]
        sql2 = "select num from zb_numbers where grouping_id='%s'" % dialing_group
        cursor.execute(sql2)
        number_data = cursor.fetchall()
        if not number_data:
            return ""
        number_list = []
        for number in number_data:
            number_list.append(number[0])
        print(number_list)
        # 随机分配
        if tactics == '1':
            random.shuffle(number_list)
            return number_list[0]
        # 轮选分配
        if tactics == '0':
            if len(number_list) < 2:
                return number_list[0]
            connect_redis19 = connect_redis(19)
            dialing_data = connect_redis19.get('dialing_group(%s)' % dialing_group)
            if not dialing_data:
                connect_redis19.set('dialing_group(%s)' % dialing_group, 0)
                return number_list[0]
            if int(dialing_data) == 0:
                connect_redis19.delete('dialing_group(%s)' % dialing_group)
                connect_redis19.set('dialing_group(%s)' % dialing_group, 1)
                return number_list[1]
            index_id = int(dialing_group) + 1
            if index_id > len(number_list) - 1:
                connect_redis19.delete('dialing_group(%s)' % dialing_group)
                connect_redis19.set('dialing_group(%s)' % dialing_group, 0)
                return number_list[0]
            else:
                connect_redis19.delete('dialing_group(%s)' % dialing_group)
                connect_redis19.set('dialing_group(%s)' % dialing_group, index_id)
                return number_list[index_id]
        cursor.close()
        connect.close()
    except Exception as e:
        print(e)
        return ""

# 查询电话号码
def query_number(thread_id):
    # 连接数据库
    connect = connect_crm()
    try:
        cursor = connect.cursor(cursor=pymysql.cursors.DictCursor)
        sql = "select mobile from zb_thread where id=%s" % thread_id
        cursor.execute(sql)
        message = cursor.fetchall()
        if not message:
            return ""
        return message[0].get('mobile', '')
    except Exception as e:
        return {"code": "503", "msg": "系统繁忙", "error": str(e)}

# 主叫侧显号码查询及分配
def query_userCli(thread_id):
    # 连接crm数据库
    connect1 = connect_crm()
    # 连接boss数据库
    connect2 = connect_boss()
    try:
        cursor1 = connect1.cursor()
        sql = "select task_id from zb_thread where id=%s"%thread_id
        cursor1.execute(sql)
        task_id = cursor1.fetchone()
        if not task_id:
            return ""
        task_id = task_id[0]
        # 查询主叫号码组ID
        sql2 = "select A_pool_id from zb_tasks where id=%s"%task_id
        cursor1.execute(sql2)
        A_pool_id = cursor1.fetchone()
        if not A_pool_id:
            return ""
        A_pool_id = A_pool_id[0]
        # 查询主叫组分配类型
        cursor2 = connect2.cursor()
        sql3 = "select tactics from zb_number_grouping where id=%s"%A_pool_id
        cursor2.execute(sql3)
        tactics = cursor2.fetchone()
        if not tactics:
            return ""
        tactics = tactics[0]
        # 查询主叫号码
        sql4 = "select num from zb_numbers where grouping_id=%s"%A_pool_id
        cursor2.execute(sql4)
        number_data = cursor2.fetchall()
        if not number_data:
            return ""
        number_list = []
        for number in number_data:
            number_list.append(number[0])
        # 随机分配
        if tactics == '1':
            random.shuffle(number_list)
            return number_list[0]
        # 轮选分配
        if tactics == '0':
            if len(number_list) < 2:
                return number_list[0]
            connect_redis19 = connect_redis(19)
            dialing_group = connect_redis19.get('dialing_group(%s)'%A_pool_id)
            if not dialing_group:
                connect_redis19.set('dialing_group(%s)'%A_pool_id,0)
                return number_list[0]
            index_id = int(dialing_group) + 1
            if index_id > len(number_list) - 1:
                connect_redis19.delete('dialing_group(%s)' % A_pool_id)
                connect_redis19.set('dialing_group(%s)' % A_pool_id, 0)
                return number_list[0]
            else:
                connect_redis19.delete('dialing_group(%s)' % A_pool_id)
                connect_redis19.set('dialing_group(%s)' % A_pool_id, index_id)
                return number_list[index_id]
        cursor1.close()
        connect1.close()
        cursor2.close()
        connect2.close()
    except Exception as e:
        print(str(e))
        return ""

query_userCli("657")

# 查询SIP分机对应的坐席号
def query_seats(sip_number):
    # 连接数据库
    connect = connect_boss()
    try:
        cursor = connect.cursor(cursor=pymysql.cursors.DictCursor)
        sql = "select agentNo from zb_agentNo where sipNumber=%s" % sip_number
        cursor.execute(sql)
        message = cursor.fetchall()
        if not message:
            return ""
        return message[0].get('agentNo', '')
    except Exception as e:
        return {"code": "503", "msg": "系统繁忙", "error": str(e)}


# 查询坐席sip账号及密码
def query_sip(*args, **kwargs):
    agentNo = kwargs.get('agentNo', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/Agents/query".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "查询成功", "data": res['data']}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 坐席登入
def seats_login(*args, **kwargs):
    # 坐席工号
    agentNo = kwargs.get('agentNo', '')
    # 坐席初始状态。1:就绪；2:未就绪；
    workStatus = kwargs.get('workStatus', '')
    # 话机类型。1:SIP话机；2:PSTN电话
    phoneType = kwargs.get('phoneType', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/AgentStatus/login".format(account,
                                                                                                                app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": str(agentNo),
            "workStatus": str(workStatus),
            "phoneType": str(phoneType)
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            # 登入成功后Redis存储状态
            redis_save(key='%s(login)' % agentNo, value='agentNo_%s' % agentNo)
            return {"code": 200, "msg": "登入成功"}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 坐席登出
def seats_logout(*args, **kwargs):
    # 坐席工号
    agentNo = kwargs.get('agentNo', '')
    # 话机类型。1:SIP话机；2:PSTN电话
    phoneType = kwargs.get('phoneType', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/AgentStatus/logout".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
            "phoneType": phoneType
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "登出成功"}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 坐席置忙
def seats_pause(*args, **kwargs):
    # 坐席工号
    agentNo = kwargs.get('agentNo', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/AgentStatus/pause".format(account,
                                                                                                                app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        return res
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 坐席置闲
def seats_ready(*args, **kwargs):
    # 坐席工号
    agentNo = kwargs.get('agentNo', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/AgentStatus/ready".format(account,
                                                                                                                app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        return res
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 查询所有坐席状态
def seats_status(*args, **kwargs):
    # 坐席工号
    agentNo = kwargs.get('agentNo', '')
    # 坐席组id
    agentNo_id = kwargs.get('agentNo_id', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/AgentStatus/query".format(account,
                                                                                                                app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
            "queueId": agentNo_id
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        return res
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 坐席SIP外呼
def seats_outbound(*args, **kwargs):
    print(kwargs)
    agentNo = kwargs.get('agentNo', '')
    userNumber = kwargs.get('userNumber', '')
    userCli = kwargs.get('userCli', '')
    # agentCli = kwargs.get('agentCli', '')
    userData = kwargs.get('userData', '')
    ringback = kwargs.get('ringback', '')
    thread_id = kwargs.get('thread_id', '')
    if thread_id:
        userNumber = query_number(thread_id)
        if not userNumber:
            return {"code": 10001, "msg": "不存在的被叫号码"}
        userCli = query_userCli(thread_id)
    try:
        agentCli = userNumber[0:3] + '****' + userNumber[7:11]
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/agentCall/makeCall".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
            "userNumber": userNumber,
            "userCli": userCli,
            "agentCli": agentCli,
            "userData": userData,
            "ringback": ringback
        }
        # print('data',json.dumps(reconsitution_data(data)))
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        # print('res',res)
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "呼出成功", "conversationSid": str(res['conversationSid'])}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}

# 坐席SIP外呼
def seats_outbound1(*args, **kwargs):
    print(kwargs)
    agentNo = kwargs.get('agentNo', '')
    userNumber = kwargs.get('userNumber', '')
    userCli = kwargs.get('userCli', '')
    # agentCli = kwargs.get('agentCli', '')
    userData = kwargs.get('userData', '')
    ringback = kwargs.get('ringback', '')
    thread_id = kwargs.get('thread_id', '')
    dialing_type = kwargs.get('dialing_type', '')
    dialing_group = kwargs.get('dialing_group','')
    if dialing_type == '0':
        userCli = dialing_group_usercli(dialing_group)
    else:
        userCli = userCli

    try:
        agentCli = userNumber[0:3] + '****' + userNumber[7:11]
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/agentCall/makeCall".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
            "userNumber": userNumber,
            "userCli": userCli,
            "agentCli": agentCli,
            "userData": userData,
            "ringback": ringback
        }
        # print('data',json.dumps(reconsitution_data(data)))
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        # print('res',res)
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "呼出成功", "conversationSid": str(res['conversationSid'])}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 坐席语音外呼
def seats_voice_outbound(*args,**kwargs):
    appid = "17aa086feb8844798120a129ea615402"
    tolist = kwargs.get('tolist','')
    froms = kwargs.get('froms','')
    contents = kwargs.get('contents','')
    times = kwargs.get('times','')
    inputrange = kwargs.get('inputrange','')
    inputvoice = kwargs.get('inputvoice','')
    inputtimeout = kwargs.get('inputtimeout','')
    repeatkey = kwargs.get('repeatkey','')
    inrangevoice = kwargs.get('inrangevoice','')
    outrangevoice = kwargs.get('outrangevoice','')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/BatchVoiceNoticesV3".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "appid": appid,
            "tolist": tolist,
            "contents": contents,
            "from": froms,
            "times": times,
            "inputrange": inputrange,
            "inputvoice": inputvoice,
            "inputtimeout": inputtimeout,
            "repeatkey": repeatkey,
            "inrangevoice": inrangevoice,
            "outrangevoice": outrangevoice,
        }
        # print('data',json.dumps(reconsitution_data(data)))
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        # print('res',res)
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "呼出成功", "conversationSid": str(res['conversationSid'])}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 用户接通后呼坐席
def user_connect_call(*args,**kwargs):
    userNumber = kwargs.get('userNumber','')
    userCli = kwargs.get('userCli','')
    userData = kwargs.get('userData','')
    greetPrompt = kwargs.get('greetPrompt','')
    agentNo = kwargs.get('agentNo','')
    queueId = kwargs.get('queueId','')
    callback = kwargs.get('callback','')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/osa/makeCall".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "userNumber": userNumber,
            "userCli": userCli,
            "userData": userData,
            "greetPrompt": greetPrompt,
            "agentNo": agentNo,
            "queueId": queueId,
            "callback": callback
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "呼出成功", "conversationSid": str(res['conversationSid'])}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 呼叫保持(坐席必须正在通话)
def call_on_hold(*args, **kwargs):
    agentNo = kwargs.get('agentNo', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/agentCall/holdCall".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "成功", "conversationSid": str(res['conversationSid'])}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 桥接呼叫
def bridging_call(*args, **kwargs):
    agentNo = kwargs.get('agentNo', '')
    conversationSid = kwargs.get('conversationSid', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/agentCall/bridge".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
            "conversationSid": conversationSid,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "成功"}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 呼叫挂断(坐席必须正在通话)
def hang_up_call(*args, **kwargs):
    agentNo = kwargs.get('agentNo', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/agentCall/releaseCall".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        if res['statusCode'] == "00000":
            return {"code": 200, "msg": "呼叫挂断成功"}
        else:
            return {"code": 403, "msg": str(res['statusMsg'])}
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 呼叫恢复
def recover_call(*args, **kwargs):
    agentNo = kwargs.get('agentNo', '')
    try:
        account = authentication().get('account', '')
        app_sid = authentication().get('app_sid', '')
        password = authentication().get('password', '')
        url = "https://api.zbtx.cc:8624/2019-08-08/Accounts/{}/Applications/{}/ccpaas/agentCall/retrieveCall".format(
            account,
            app_sid)
        token = "Basic " + str(base64.b64encode((account + ":" + password).encode('utf-8')), "utf-8")
        headers = {
            "Authorization": token,
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = {
            "agentNo": agentNo,
        }
        res = requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data))).json()
        return res
    except Exception as e:
        return {"code": 10001, "msg": "请检查传入参数", "error": str(e)}


# 事件推送至BOSS
def incident_push_boss(request):
    try:
        url = "http://172.16.235.8:8281/call_event_receive/"
        # url = "http://39.102.37.193:2035/call_event_receive/"
        headers = {
            "Content-Type": "application/json;charset=utf-8",
            "Accept": "application/json"
        }
        data = request.data
        requests.post(url=url, headers=headers, data=json.dumps(reconsitution_data(data)))
        return
    except Exception as e:
        print(e)
        return


# 事件转手websocket
def pass_no_websocket(*args, **kwargs):
    setas = kwargs.get('setas', '')
    data = kwargs.get('data', '')
    channel_layer = get_channel_layer()
    async_to_sync(channel_layer.group_send)(
        'notice_%s' % setas,  # 构造Channels组名称
        {
            "type": "system_message",
            "message": json.dumps(data),
        }
    )

# print(query_sip(agentNo='3004'))
# print(seats_login(agentNo='3000',workStatus='1',phoneType='1'))
# print(seats_pause(agentNo='3000'))
# print(seats_ready(agentNo='3000'))
# print(seats_status(agentNo_id="Q2199"))
# print(seats_outbound(agentNo='3004',userNumber='18400000000',userCli='02860695193',userData={'account':'智博天下','Apool':'测试A池','docking':'测试对接网关','ground':'测试落地网关','agent_acc':'测试结算账户','userCli':'051880702462'}))
# print(seats_outbound(agentNo='3004',userNumber='13389545453',userCli='02860695190'))
# print(user_connect_call(userNumber="13389545453",userCli="02860695190",userData={'account':'测试账户','Apool':'测试A池','docking':'测试对接网关','ground':'测试落地网关','agent_acc':'测试结算账户','userCli':''},greetPrompt="",agentNo="3004"))
# print(call_on_hold(agentNo='3000',userNumber='13389545453+'))
# print(bridging_call(agentNo='5058'))
# print(hang_up_call(agentNo='3000',userNumber='13389545453'))
# print(recover_call(agentNo='3000',userNumber='13389545453'))
# print(seats_logout(agentNo='3004'))
